package org.lee.service;

import java.util.List;

import org.lee.bean.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.joinway.framework.data.jdbc.repository.TableRepository;

@Service
public class PrimaryService {

	@Autowired protected TableRepository repository;
	
	public List<Person> findAllPerson() throws Exception {
		return repository.find(Person.class, "select * from person");
	}
	
	@Transactional(value="transactionManager",rollbackFor=Throwable.class)
	public Person addPerson(String name) throws Exception {
		Person person = new Person();
		person.setName(name);
		Person p = repository.save(person);
		
		return p;
	}
}
